package org.dolphin.entity.misc;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import org.dolphin.base.constant.DatabaseAttribute;
import org.dolphin.entity.interceptor.Auditable;
import org.dolphin.entity.security.User;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.util.ObjectUtils;

@Entity
@Table(name = "MS_DUE_DATE_PERIOD", uniqueConstraints = {@UniqueConstraint(columnNames = {"CODE"}, name = "UQ_MS_DUE_DATE_PERIOD_CODE")})
public class DueDatePeriod implements Serializable, Auditable {
  private static final long serialVersionUID = 2749089485301618879L;
  private String id;
  private String code;
  private Integer year;
  private Integer month;
  private Integer week;
  private Integer day;
  private Long version;
  private User createdBy;
  private User updatedBy;
  private Date createdDate;
  private Date updatedDate;

  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    } else if (obj instanceof DueDatePeriod) {
      DueDatePeriod oth = (DueDatePeriod) obj;
      return ObjectUtils.nullSafeEquals(getId(), oth.getId());
    }
    return false;
  }

  @Column(name = "CODE", nullable = false, length = 200)
  public String getCode() {
    return code;
  }

  @Override
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "CREATED_BY", nullable = false)
  @ForeignKey(name = "FK_MS_DUE_DATE_PERIOD_CREATED_BY")
  public User getCreatedBy() {
    return createdBy;
  }

  @Override
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "CREATED_DATE", nullable = false)
  public Date getCreatedDate() {
    return createdDate;
  }

  @Column(name = "PERIOD_DAY", nullable = false)
  public Integer getDay() {
    return day;
  }

  @Id
  @GeneratedValue(generator = "uuid2")
  @GenericGenerator(name = "uuid2", strategy = "org.dolphin.base.id.generator.CustomUUIDGenerator")
  @Column(name = "ID", nullable = false, length = DatabaseAttribute.ID_LENGTH)
  public String getId() {
    return id;
  }

  @Column(name = "PERIOD_MONTH", nullable = false)
  public Integer getMonth() {
    return month;
  }

  @Override
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "UPDATED_BY", nullable = true)
  @ForeignKey(name = "FK_MS_DUE_DATE_PERIOD_UPDATED_BY")
  public User getUpdatedBy() {
    return updatedBy;
  }

  @Override
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "UPDATED_DATE", nullable = true)
  public Date getUpdatedDate() {
    return updatedDate;
  }

  @Version
  @Column(name = "VERSION_NO", nullable = false)
  public Long getVersion() {
    return version;
  }

  @Column(name = "PERIOD_WEEK", nullable = false)
  public Integer getWeek() {
    return week;
  }

  @Column(name = "PERIOD_YEAR", nullable = false)
  public Integer getYear() {
    return year;
  }

  @Override
  public int hashCode() {
    int hash = ObjectUtils.nullSafeHashCode(getId());
    return hash;
  }

  public void setCode(String code) {
    this.code = code;
  }

  @Override
  public void setCreatedBy(User createdBy) {
    this.createdBy = createdBy;
  }

  @Override
  public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
  }

  public void setDay(Integer day) {
    this.day = day;
  }

  public void setId(String id) {
    this.id = id;
  }

  public void setMonth(Integer month) {
    this.month = month;
  }

  @Override
  public void setUpdatedBy(User updatedBy) {
    this.updatedBy = updatedBy;
  }

  @Override
  public void setUpdatedDate(Date updatedDate) {
    this.updatedDate = updatedDate;
  }

  public void setVersion(Long version) {
    this.version = version;
  }

  public void setWeek(Integer week) {
    this.week = week;
  }

  public void setYear(Integer year) {
    this.year = year;
  }
}
